<template>
  <div id="transer">
    <div style="background-color: white;padding: 10px;">
      <el-table :data="TranList" border style="width: 700px">
        <el-table-column type="index" align="center" label="序号" width="80" />
        <el-table-column prop="ad_name" label="被转移地区" />
        <el-table-column prop="apply_ad_name" label="原隶属于" />
        <el-table-column prop="target_ad_name" label="转移目标" />
        <el-table-column label="操作">
          <template #default="scope">
            <div v-show="scope.row.apply_ad_code != usercode">
              <el-button type="success" @click="t_aggree(scope.row)">接受</el-button>
              <el-button type="danger" @click="t_reject(scope.row)">驳回</el-button>
            </div>
            <div v-show="scope.row.apply_ad_code == usercode">
              <el-button type="warning" @click="t_backout(scope.row)">撤销</el-button>
            </div>
          </template>
        </el-table-column>
      </el-table>
    </div>

  </div>
</template>

<script setup>
import { ElMessage, ElMessageBox } from 'element-plus';
import { ref, onMounted, reactive } from 'vue';
import $sys from '../../api/sys';
const usercode = ref("");
onMounted(() => {
  getTranList();
  usercode.value = localStorage.getItem("code");
});
const page = reactive({
  pagenum: 1,
  pagesize: 999
});
const TranList = ref([]);
function getTranList() {
  $sys.getTransList(page).then(res => {

    if (res.code == 200) {
      let filtearr = [];
      res.data.result.forEach((item, index) => {
        if (item.state == 1) {
          filtearr.push(item);
        }
      });
      TranList.value = filtearr;
    }
  });
}
function t_aggree(e) {
  let tsid = e.id;
  ElMessageBox.confirm(
    '确定接受该转移申请吗?',
    '警告',
    {
      confirmButtonText: '确定',
      cancelButtonText: '取消',
      type: 'warning',
    }
  ).then(() => {
    $sys.agreeTrans(tsid).then(res => {
      if (res.code == 200) {
        ElMessage({
          message: '操作成功!',
          type: 'success'
        });
        getTranList();
      } else {
        ElMessage({
          message: res.message,
          type: 'warning'
        });
      }
    });
  }).catch(() => {

  });
}
function t_reject(e) {
  let tsid = e.id;
  ElMessageBox.confirm(
    '确定驳回该转移申请吗?',
    '警告',
    {
      confirmButtonText: '确定',
      cancelButtonText: '取消',
      type: 'warning',
    }
  ).then(() => {
    $sys.rejectTrans(tsid).then(res => {
      if (res.code == 200) {
        ElMessage({
          message: '操作成功!',
          type: 'success'
        });
        getTranList();
      } else {
        ElMessage({
          message: res.message,
          type: 'warning'
        });
      }
    });
  }).catch(() => {

  });
}
function t_backout(e) {
  let tsid = e.id;
  ElMessageBox.confirm(
    '确定取消该转移申请吗?',
    '警告',
    {
      confirmButtonText: '确定',
      cancelButtonText: '取消',
      type: 'warning',
    }
  ).then(() => {
    $sys.backoutTrans(tsid).then(res => {
      if (res.code == 200) {
        ElMessage({
          message: '操作成功!',
          type: 'success'
        });
        getTranList();
      } else {
        ElMessage({
          message: res.message,
          type: 'warning'
        });
      }
    });
  }).catch(() => {

  });
}
</script>

<style scoped lang="less">
#transer {
  padding: 20px;
}
</style>
